$(function () {
    /*会员列表*/
    $("#clientDataGrid").datagrid({
        url: "/client/query.do",
        height:253,
        striped: true,
        fitColumns: true,
        singleSelect: true,
        toolbar: "#clientdata_toolbar",
        /*点击行事件*/
        onSelect: function (index, row) {
            /*具体会员信息*/
            ($("#clientTab td span[tag='name']")).html(row.name);
            ($("#clientTab td span[tag='level']")).html(row.level);
            ($("#clientTab td span[tag='balance']")).html(row.balance);
            ($("#clientTab td span[tag='number']")).html(row.number);
            ($("#clientTab td span[tag='birthday']")).html(row.birthday);
            ($("#clientTab td span[tag='integral']")).html(row.integral);
            /*给表单的数据*/
            $("#clientId").val(row.id);
        },
        columns: [[
            {field: 'name', title: '会员名称', width: 90, align: 'center',styler : function(value, row, index) {
                    return 'border:0;';
                }},
            {field: 'level', title: '等级', width: 90, align: 'center',styler : function(value, row, index) {
                    return 'border:0;';
                }},
            {field: 'sex', title: '性别', width: 90, align: 'center',styler : function(value, row, index) {
                    return 'border:0;';
                }},
            {field: 'tel', title: '电话', width: 180, align: 'center',styler : function(value, row, index) {
                    return 'border:0;';
                }}
        ]]
    })

    /*积分明细列表*/
    $("#integralitemData").datagrid({
        url: "/integralItem/query.do",
        fit: true,
        fitColumn: true,
        striped: true,
        pagination: true,
        toolbar:'#itemdata_toolbar',
        columns: [[

            {field:'client.number', title:'卡号',width: 80, align: 'center',formatter:function (value, row, index) {
                    return row?row.client.number:'';
                }},
            {
                field: 'operation', title: '操作', width: 80, align: 'center', formatter: function (value, row, index) {
                    return value == 1 ? "<span style='color: green;font-weight: normal;font-size: unset'>充值</span>" : "<span style='color: red;font-weight: normal;font-size: unset'>消费</span>"
                }
            },
            {field:'client.name', title:'姓名',width: 80, align: 'center',formatter:function (value, row, index) {
                    return row?row.client.name:'';
                }},
            {field:'client.level', title:'等级',width: 80, align: 'center',formatter:function (value, row, index) {
                    return row?row.client.number:'';
                }},
            {field:'changeIntegral',title:'变动值',width: 80, align: 'center'},
            {field:'info',title:'备注',width: 170, align: 'center'}
        ]]
    })

    /*高级查询事件*/
    $("#keyword").searchbox({
        searcher: function (value, name) {
            $("#integralitemData").datagrid('load', {
                keyword: value
            })
        }
    })
})

function save() {
    var id = $("#clientId").val();
    if (id==0) {
        $.messager.alert("温馨提示", "请选择会员", "error");
        return;
    }
    $.messager.confirm("温馨提示", "确定充值吗?", function (r) {
        if (r) {
            $("#rechargeService_form").form('submit', {
                url: "/integralItem/save.do",
                success: function (data) {
                    data = $.parseJSON(data);
                    if (data.success) {
                        $.messager.alert("温馨提示", "充值成功", "info", function () {
                            /*清表单数据*/
                            $("#recharge_form").form('clear');
                            /*刷新明细*/
                            window.location.reload();
                            $("#myTabs").tabs('select',"会员充值");
                        });
                    } else {
                        $.messager.alert("温馨提示", data.msg, "error");
                    }
                }
            })
        }
    })
}